#ifndef _META_SET_H_
#define _META_SET_H_

#include "json.h"


// meta model for the data struct 
typedef struct META {
	char* name;		// the name of member
	uint16 type;	// member type
	uint16 offset; // offset of member from the type head
	union {
		struct META* child; // support the child struct type
		int count;	// indicate the count of member when the member is a array type
	};
	char* alias; // alias for the parameter, use the "name" if this is NULL
} META;

// define the meta for struct type
// x- the struct of type
#define METAS_PARA(x) {#x, meta##x}

#ifdef __compiler_offsetof 
#define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER) 
#else 
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 
#endif 

#define DECLARE_MATE_BEGIN(XXX) \
	META meta_##XXX[] = { 
#define DECLARE_MATE_END() \
	{0, 0, 0, 0, 0}};

// describe the struct meta
// type - the struct name 
// member - the struct member name
// class - the class name of struct member
// childMeta - the meta data of struct member, if the struct member is a struct type, otherwise set NULL
// alias - the alias of struct member, if set as 0, use the struct member name.
#define PARAMETER(type, member, class, childMeta, alias) {#member, class, offsetof(type, member), childMeta, alias}

META* getMetabyName(char* name);

#endif
